/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package autenticacionmodulo;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.Calendar;
import java.util.Date;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Node;

/**
 *
 * @author Larry
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, InterruptedException {
	Node nodo;
	try {
        // Call Web Service Operation
	    ec.edu.espol.academico.webservices.DirectorioEspol service = new ec.edu.espol.academico.webservices.DirectorioEspol();
	    ec.edu.espol.academico.webservices.DirectorioEspolSoap port = service.getDirectorioEspolSoap12();
	    // TODO initialize WS operation arguments here
	    java.lang.String varUser = "lbeltran";
	    java.lang.String varContrasenia = "200211324";
	    // TODO process result here
	    ec.edu.espol.academico.webservices.DatosUsuarioResponse.DatosUsuarioResult result = port.datosUsuario(varUser, varContrasenia);
	    System.out.println("Result = " + result);
	    nodo = (Node) result.getAny();

	    CargadorXml cargador = new CargadorXml();
	    NewDataSet obj = cargador.getNewDataSet(nodeToString(nodo.getFirstChild()));
	    System.out.println("obj: " + obj.getClass());
	    System.out.println("Now I see it");

	    System.out.println("Apellidos: " + obj.getDatosUsuario().getApellidos());
	    System.out.println("Nombres:  " + obj.getDatosUsuario().getNombres());
	    System.out.println("Matricula: " + obj.getDatosUsuario().getMatricula());
	    System.out.println("Cedula: " + obj.getDatosUsuario().getCedula());

	} catch (Exception ex) {
	    ex.printStackTrace();
	}

    }

    public static String nodeToString(Node ele) throws TransformerException {
// Set up the output transformer
	TransformerFactory transfac = TransformerFactory.newInstance();
	Transformer trans = transfac.newTransformer();
	trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
	trans.setOutputProperty(OutputKeys.INDENT, "yes");

// Print the DOM node
	StringWriter sw = new StringWriter();
	StreamResult result2 = new StreamResult(sw);
	DOMSource source = new DOMSource(ele);
	trans.transform(source, result2);
	String xmlString = sw.toString();
	return xmlString;


    }

    public static void printNodos(Node ele) {

	try {
// Set up the output transformer
	    TransformerFactory transfac = TransformerFactory.newInstance();
	    Transformer trans = transfac.newTransformer();
	    trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
	    trans.setOutputProperty(OutputKeys.INDENT, "yes");

// Print the DOM node
	    StringWriter sw = new StringWriter();
	    StreamResult result2 = new StreamResult(sw);
	    DOMSource source = new DOMSource(ele);
	    trans.transform(source, result2);
	    String xmlString = sw.toString();
	    System.out.println(xmlString);
	} catch (TransformerException e) {
	    e.printStackTrace();
	}
    }
}
